package com.lxh.lxhcrm.controller.productManagement;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.*;
import com.lxh.lxhcrm.model.service.ProductService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开发团队 ：lxh
 * 开发人员 ：gmx
 * 开发时间 ：2020/1/9 10:34
 * 类的名称 ：ProductController
 * 类的描述 ：产品模块的controller，进行前后端的数据传输控制
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    ProductService productService;
    /*
     * 查询
     * */
    //产品列表查询
    @RequestMapping("/product-list")
    public Map<String,Object> productList(Integer currPage,Integer pageSize,String searchText,Integer selectModel,Integer proClassilyId){
        //分页
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> pro=new HashMap<>();
        List<ProDetail> allProduct=productService.findAllProduct(searchText,selectModel,proClassilyId);
        pro.put("data",allProduct);
        pro.put("total",page.getTotal());
        return pro;
    }
    //无分页查询产品
    @RequestMapping("/all-product")
    public List<ProDetail> allProduct(){
        List<ProDetail> proDetails=productService.allProduct();
        return proDetails;
    }
    //查询所有属性
    @RequestMapping("/attribute-list")
    public List<Attribute> attributeList(){
        List<Attribute> attribute=productService.findAllAttribute();
        return attribute;
    }
    //产品分类查询，树形结构
    @RequestMapping("/classily-list")
    public List<ProClassily> classilyList(){
        List<ProClassily> classily=productService.findAllClassily();
        return classily;
    }
    //产品分类列表查询
    @RequestMapping("/classily-list2")
    public List<ProClassily> classilyList2(){
        List<ProClassily> classily=productService.findClassily();
        return classily;
    }
    //产品分类查询
    @RequestMapping("/only-classily")
    public List<Classily> classilieList3(){
        List<Classily> classily=productService.onlyClassily();
        return classily;
    }
    //查询合同中销售产品数量数据
    @RequestMapping("/findCPRoNum")
    public List<Map<String,Object>> findCPRoNum(Integer yearTime,Integer monthTime){
        return productService.findCPRoNum(yearTime, monthTime);
    }
    //查询采购中产品数量数据
    @RequestMapping("/findCaiProNum")
    public List<Map<String,Object>> findCaiProNum(Integer yearTime,Integer monthTime){
        return productService.findCaiProNum(yearTime, monthTime);
    }
    /*
    * 新增
    * */
    //产品分类新增
    @RequestMapping("/add-classily")
    public void addClassily(@RequestBody ProClassily classily){
        productService.addClassily(classily);
    }
    //产品属性新增
    @RequestMapping("add-attribute")//新增属性名
    public void addAttribute(@RequestBody Attribute attribute){productService.addAttribute(attribute);}
    @RequestMapping("add-ability")//新增属性值
    public void  addAbility(@RequestBody Ability ability){productService.addAbility(ability);}
    //产品新增
    @RequestMapping("/add_product")
    public void addProduct(@RequestBody Product product){
        System.out.println(product.getProDetails());
        productService.addProduct(product);
    }
    //产品详情新增
    @RequestMapping("/add_prodetail")
    public void addProDetail(@RequestBody ProDetail proDetail){
        productService.addProDetail(proDetail);
    }
    //为产品添加属性
    @RequestMapping("/add_abicen")
    public void addAbicen(@RequestBody AbiCen abiCen){
        productService.addAbiCen(abiCen);
    }
    /*
     * 修改
     * */
    //修改产品状态，一键下架所选产品
    @RequestMapping("/change-proon")
    public void changeProOn(Integer proDetailId){productService.changeProOn(proDetailId);}
}
